package com.dt76.smallloanbackendservice.controller.etao;

import com.dt76.smallloanbackendservice.pojo.etao.Role;
import com.dt76.smallloanbackendservice.service.etao.RoleService;
import com.dt76.smallloanbackendservice.utils.Page;
import com.dt76.smallloanbackendservice.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class RoleController {

    @Autowired
    private RoleService roleService;

    @RequestMapping("/getAllRole")
    @ResponseBody
    public Page getAllRole(@RequestParam Integer pageIndex) {
        return roleService.getAllRole(pageIndex);
    }

    @RequestMapping("/getRoleById")
    @ResponseBody
    public Role getRoleById(@RequestParam Integer rId) {
        return roleService.getRoleById(rId);
    }

    @RequestMapping("/getRoleBydId")
    @ResponseBody
    public List<Role> getRoleByDid(@RequestParam Integer dId) {
        return roleService.getRoleBydId(dId);
    }

    @RequestMapping("/updateRole")
    @ResponseBody
    public Result updateRole(@RequestBody Role role) {
        Result result = new Result();
        result.setSuccess(roleService.updRole(role));
        return result;
    }

    @RequestMapping("/addRole")
    @ResponseBody
    public Result addRole(@RequestBody Role role) {
        Result result = new Result();
        result.setSuccess(roleService.addRole(role));
        return result;
    }

    @RequestMapping("/delRole")
    @ResponseBody
    public Result delRole(@RequestParam Integer rId) {
        Result result = new Result();
        result.setSuccess(roleService.delRole(rId));
        return result;
    }

}
